import React from 'react';
import ReactDom from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import ErrorBoundary from './tools/ErrorBoundary';

import App from './App';
import './index.less';

class Index extends React.Component {
    render() {
        return (
            <Router>
                <ErrorBoundary
                    fallbackRender={({ state, onResetErrorBoundary }) => {
                        return (
                            <div>
                                <h1>组件错误</h1>
                                <button
                                    onClick={() => {
                                        console.log(state);
                                    }}
                                >
                                    控制台打印错误信息
                                </button>
                                <button
                                    onClick={() => {
                                        onResetErrorBoundary();
                                    }}
                                >
                                    重新渲染组件
                                </button>
                            </div>
                        );
                    }}
                >
                    <App />
                </ErrorBoundary>
            </Router>
        );
    }
}
ReactDom.render(<Index />, document.getElementById('app'));
